class AcessoController {

    def springSecurityService

    def index = {
        if (springSecurityService.isLoggedIn()) {
            def user = Pessoa.get(springSecurityService.principal.id)
            session["pessoa"] = user
            
            if (user.authorities.contains(Role.findByAuthority('ROLE_ADMIN'))) {
                redirect uri: '/pessoa'
            }else{
                if (user.authorities.contains(Role.findByAuthority('ROLE_ATENDENTE'))) {
                    redirect uri: '/pessoa'
                }else{
                    if (user.authorities.contains(Role.findByAuthority('ROLE_ESTAGIARIO'))) {
                        redirect uri: '/estagiario'
                    }else{
                        if (user.authorities.contains(Role.findByAuthority('ROLE_UC'))) {
                            redirect uri: '/unidadeConcedente'
                        }else{
                            if (user.authorities.contains(Role.findByAuthority('ROLE_IE'))) {
                                redirect uri: '/instituicaoEnsino'
                            }else{
                                redirect uri: '/'
                            }
                        }
                    }
                }
            }
        }
        else {
            redirect uri: '/login'
        }
    }
}
